Skip to content

ao_two_e_ints: same-side Schwartz bound sqrt((ik|ik)) (fix #419) - #422

Merged
scemama merged 2 commits into
dev-stablefrom
issue419-schwartz-sameside
Nov 18, 2026
Merged

scemama merged 2 commits into
dev-stablefrom
issue419-schwartz-sameside

Conversation

@scemama

@scemama scemama commented Nov 18, 2026

Copy link
Copy Markdown
Member

Fixes #419.

One-line change in the ao_two_e_integral_schwartz provider:

-      ao_two_e_integral_schwartz(i,k) = dsqrt(ao_two_e_integral(i,i,k,k))
+      ao_two_e_integral_schwartz(i,k) = dsqrt(ao_two_e_integral(i,k,i,k))

ao_two_e_integral_zero(i,j,k,l) tests the integral whose electron pairs are
(i,k) and (j,l), i.e. (ik|jl) (the same reading as
ao_two_e_integral(i,k,j,l)). By the direct Cauchy-Schwarz inequality,

|(ik|jl)| <= sqrt((ik|ik) * (jl|jl)),

the self-energy of each product AO, so the per-pair factor must be
sqrt((ik|ik)). The old cross-pairing sqrt((ii|kk)(jj|ll)) is not a
proven bound on (ik|jl), and in stretched two-center geometries it
decays only as 1/R, so at the default ao_integrals_threshold of 1e-15
it effectively never triggers. This also aligns the matrix with the erf
provider, which already uses the same-side factor
(providers_ao_erf.irp.f:104).

Call sites audited (1st+3rd / 2nd+4th arguments form the electron pairs):

  • Cholesky on-the-fly (cholesky.irp.f:420), the default SCF path:
    zero(L1,D1,L2,D2) — the bound is now rigorous for the (L1L2|D1D2)
    integral actually computed;
  • Fock loops (fock_matrix_hf.irp.f:61, fock_matrix_ks.irp.f:58):
    local_threshold = schwartz(k,l)*schwartz(i,j) becomes the exact
    Cauchy-Schwarz bound on the quartet's base integral (kl|ij) (it was a
    cross-pairing that is not a bound), tightening the per-quartet
    primitive down-screening;
  • map lookups (map_integrals.irp.f); the 1/r12 map uses its own erf
    matrix, unchanged.

Also fixes a convention slip in the ao_two_e_integral_zero docstring
(it documented (ij|kl); the convention is (ik|jl)).

Verification (B2 @ 3.0 A, 6-31G, 18 AO; full build, gfortran 13.4):

  • 3-D Gauss-Legendre quadrature check: sqrt((ik|ik)(jl|jl)) >= |(ik|jl)| on a 4-distinct-primitive grid, tight (within ~1.1x in the
    Fock convention); the old factor is a looser bound there (up to ~4000x);
  • A/B at threshold_ao = 1e-4 (only the provider line flipped, same
    build): identical SCF energy, -49.0123445289287 — no observable change
    in this system, consistent with the "severity: low" assessment;
  • new regression test B-B_screening in 10.hf.bats: SCF at
    threshold_ao = 1e-8 converges to -48.9950589230371, within 3.8e-7 a.u.
    of the unscreened reference -48.9950585434279 (bats tolerance 1e-5);
    passes with the default configuration (Cholesky on). The existing B-B
    test is unaffected.

CI compiles the PR as usual.

ao_two_e_integral_zero(i,j,k,l) tests the integral with electron pairs
(i,k) and (j,l), i.e. (ik|jl). By Cauchy-Schwarz,
|(ik|jl)| <= sqrt((ik|ik)(jl|jl)), so the per-pair factor must be
sqrt((ik|ik)) - the self-energy of the product AO ik - not the old
cross-pairing sqrt((ii|kk)), which is not a proven bound on (ik|jl)
and decays only as 1/R in stretched two-center geometries. Same factor
as the erf matrix (providers_ao_erf.irp.f:104).

Also fixes the (ij|kl)/(ik|jl) convention slip in the
ao_two_e_integral_zero docstring, and adds the B-B_screening regression
test (SCF at ao_integrals_threshold=1e-8 stays within 1e-5 a.u. of the
unscreened reference on stretched B2).
@scemama
scemama merged commit 66de718 into dev-stable Nov 18, 2026
3 of 4 checks passed
scemama added a commit that referenced this pull request Nov 19, 2026
On the map path (do_ao_cholesky = False) the dispatcher
ao_two_e_integral routes to ao_two_e_integral_schwartz_accel
whenever the product of the primitive counts exceeds 1024, and
that accelerator skips primitive quartets with the absolute
threshold ao_integrals_threshold**2. The Schwartz screening
factors ao_two_e_integral_schwartz(i,k) = sqrt((ik|ik)) were
therefore computed from zeroed (or under-summed) diagonals, and
the AO-level CS test then dropped integrals far above the
threshold: on the (H2O)4 chain, cc-pVDZ, threshold 1e-15,
43/5050 factors came out exactly 0 and 34 482 integrals >= 1e-15
were dropped (largest 3.9e-9). The Cholesky path was unaffected
(do_schwartz_accel is false when do_ao_cholesky), which is why
the defect survived the sqrt((ik|ik)) fix of #422.

The full primitive sum (the dispatcher's final branch, moved
verbatim) is now ao_two_e_integral_full, and the provider
ao_two_e_integral_schwartz uses
dsqrt(dabs(ao_two_e_integral_full(i,k,i,k))) - the same pattern
the cGTO providers use since #421 (dabs: a vanishing diagonal
can be negative by rounding). Dispatcher behaviour is unchanged:
its last branch is now a single call.

The same defect existed on the long-range (erf) path, which
routes to ao_two_e_integral_schwartz_accel_erf unconditionally
above 1024 primitives; ao_two_e_integral_erf_full and
ao_two_e_integral_erf_schwartz get the same treatment.
scemama added a commit that referenced this pull request Nov 19, 2026
Per the proposal in issue #419: the test
ao_overlap_abs(j,l)*ao_overlap_abs(i,k) < ao_integrals_threshold
is not a bound on (ik|jl) - it dropped integrals up to ~10x the
threshold (5-8 bohr 1s example: S_ik*S_jl ~ 1e-15 while
(ik|jl) = 1.1e-15). The rigorous CS bound
sqrt((ik|ik)(jl|jl)) with exact diagonals (previous commit)
subsumes it at zero cost: the factors are already provided.

The BEGIN_DOC is rewritten: the integral tested is (ik|jl)
(1st+3rd arguments = pair 1, 2nd+4th = pair 2), the real-GTO
test is the rigorous Cauchy-Schwarz bound, and no integral
above ao_integrals_threshold is screened. This also restores
the doc fix that the merge 66de718 of #422 dropped.
@scemama
scemama deleted the issue419-schwartz-sameside branch November 21, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant